Three Little Circles

The "Hello World" (or Maxwell's Equations) of d3, Three Little Circles introduces all of the main concepts in d3, which gives you a pretty good grounding in data visualization, JavaScript, and SVG. Let's try out some circles in livecoder.

First, we need Livecoder, and traitlets, the Observer/Observable pattern used in building widgets.


In [1]:
from livecoder.widgets import Livecoder
from IPython.utils import traitlets as T


:0: FutureWarning: IPython widgets are experimental and may change in the future.

Livecoder by itself doesn't do much. Let's add a traitlet for where we want to draw the circles (the cx attribute).


In [2]:
class ThreeCircles(Livecoder):
    x = T.Tuple([1, 2, 3], sync=True)

Notice the sync argument: this tells IPython that it should propagate changes to the front-end. No REST for the wicked?


In [3]:
circles = ThreeCircles(description="three-circles")
circles.description


Out[3]:
'three-circles'

Almost there! To view our widget, we need to display it, which is the default behavior by just having the widget be the last line of a code cell.


In [4]:
circles